package bishi.tongcheng;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class demo2 {
    public int[] analyze_response_times (int[] times) {
        int[] demo = new int[times.length];

        for(int i = 0;i < times.length;i++) {
            demo[i] = times[i];
        }
        int time95 = get95Time(demo);


        List<Integer> ret = findOut(times);
        int[] rest = new int[ret.size() + 1];
        rest[0] = time95;
        for(int i = 1;i <= ret.size();i++) {
            rest[i] = ret.get(i - 1);
        }
        return  rest;
    }
    public static int get95Time(int[] times) {
        if(times.length == 0) {
            return -1;
        }
        Arrays.sort(times);
        int index = (int) ((times.length-0.95) - 1);
        if(index < 0) {
            index = 0;
        }
        return times[index];
    }

    public static List<Integer> findOut(int[] times) {

        boolean find = true;
        List<Integer> ret = new ArrayList<>();

        if(times.length == 0) {
            ret.add(-1);
            return ret;
        }

        int sum = 0;
        for(int x : times) {
            sum += x;
        }
        int avg = sum/times.length;
        for(int i  = 0;i < times.length;i++) {
            int time = times[i];
            if(time > avg*2 ) {
                ret.add(i);
                find = false;
            }
        }
        if(find) {
            ret.add(-1);
            return ret;
        }
        return ret;
    }
}
